package tts.controller.users;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;

import tts.controller.RedirectAction;
import tts.dao.RolesHome;
import tts.dao.UsersHome;
import tts.model.Users;

public class Edit extends RedirectAction{

	//fields
	private static final long serialVersionUID = 7369203581207143122L;
	@Autowired
	private UsersHome usersHome;
	@Autowired
	private RolesHome rolesHome;
	private String username;
	private Users userEdit;
	private ArrayList<String> rstrings;
	private ArrayList<String> gstrings;

	//get & set
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public Users getUserEdit() {
		return userEdit;
	}
	public void setUserEdit(Users userEdit) {
		this.userEdit = userEdit;
	}
	public ArrayList<String> getRstrings() {
		return rstrings;
	}
	public void setRstrings(ArrayList<String> rstrings) {
		this.rstrings = rstrings;
	}
	public ArrayList<String> getGstrings() {
		return gstrings;
	}
	public void setGstrings(ArrayList<String> gstrings) {
		this.gstrings = gstrings;
	}
	
	//methods
	public String edit() {
		try {
			usersHome.update(this.username, this.userEdit, rstrings, gstrings);
		} catch (RuntimeException e) {
			addActionError(e.getMessage());
			return ERROR;
		}
		addActionMessage(getText("user.updated"));
		return SUCCESS;
	}
}